package org.as3search.providers {
	/*
	 * as3search - http://code.google.com/p/as3search
	 * Copyright (c) 2009-2010 by respective authors. All rights reserved.
	 *
	 * This library is free software; you can redistribute it and/or modify it under the
	 * terms of the GNU Lesser General Public License as published by the Free Software
	 * Foundation; either version 2.1 of the License, or (at your option) any later
	 * version.
	 *
	 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
	 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
	 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
	 *
	 * You should have received a copy of the GNU Lesser General Public License along
	 * with this library; if not, write to the Free Software Foundation, Inc.,
	 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
	 */
	
	import flash.errors.IllegalOperationError;
	
	import org.flexunit.Assert;
	
	/**
	 * 
	 */
	public class ObjectSearchProviderTestCase {
		
		private var classToTestRef:org.as3search.providers.ObjectSearchProvider;
		
		public function ObjectSearchProviderTestCase() {
			
		}
		
		[Before]
		public function setup():void {
			this.classToTestRef = new ObjectSearchProvider();
			this.classToTestRef.target = {a:"b"};
		}
		
		[Test]
		public function testTarget():void {
			var targ:Object = {b: "C"};
			classToTestRef.target = targ;
			Assert.assertTrue("failed to wrap the target",
				classToTestRef.target[0] === targ);
		}
		
		[Test]
		public function testHasNext():void {
			Assert.assertTrue("failed to return true when it has an element",
				classToTestRef.hasNext());
			classToTestRef.next();
			Assert.assertFalse("failed to reach the end of the list",
				classToTestRef.hasNext());
		}
		
		[Test]
		public function testLength():void {
			Assert.assertEquals("length should equal 1",
				classToTestRef.length, 1);
		}
		
		[Test]
		public function testNext():void {
			Assert.assertNotNull("next() should not return null in this case",
				classToTestRef.next());
			try {
				classToTestRef.next();
				Assert.fail("did not throw an error when reaching the end of the collection");
			} catch (e:IllegalOperationError) {
//				pass
			}
		}
		
		[Test]
		public function testReset():void {
			classToTestRef.next();
			Assert.assertFalse("we should now be at the end of the 'collection'",
				classToTestRef.hasNext());
			classToTestRef.reset();
			Assert.assertTrue("reset() failed to return us to the beginning of the 'collection'",
				classToTestRef.hasNext());
		}
	}
}